package com.tywj.panda.driver.performance

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.tywj.panda.customer.common.tool.MoneyTool
import com.tywj.panda.customer.common.widget.recyclerview.MyBaseAdapter
import com.tywj.panda.driver.R
import com.tywj.panda.driver.entity.DriverPerformanceEntity
import com.tywj.lib.core.common.util.ResourcesUtil
import com.tywj.lib.core.widget.recycleview.adapter.BaseViewHolder

/**
 * 行程中的item 手动控制显示或隐藏
 */
//时间显示为一维数组，行程则为二维数组
class DriverWaterAdapter : MyBaseAdapter<DriverPerformanceEntity.DataBean>(R.layout.driver_recycle_item_performance) {

    override fun convert(helper: BaseViewHolder, item: DriverPerformanceEntity.DataBean) {
        super.convert(helper, item)

        helper.setText(R.id.tvBusLine, item.lineName)
        helper.setText(R.id.tvMoney, MoneyTool.formatFen(item.amount))
        helper.setText(R.id.tvOrderNo, "用户订单ID:" + item.orderId)
        helper.setText(R.id.tvNum, "乘客数:" + item.passengerNum)
    }

    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        super.onAttachedToRecyclerView(recyclerView)
        recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {

                val position = parent.getChildLayoutPosition(view)
                if (position != RecyclerView.NO_POSITION) {
                    when (position) {
                        // 第一个
                        0 -> {
                            outRect.top = ResourcesUtil.getDimensionPixelSize(R.dimen.dp_10)
                            outRect.bottom = ResourcesUtil.getDimensionPixelSize(com.tywj.navigation.R.dimen.dp_1)
                        }
                        // footer
                        this@DriverWaterAdapter.data.size + this@DriverWaterAdapter.headerLayoutCount -> outRect.top = 0
                        // 其他
                        else -> outRect.bottom = ResourcesUtil.getDimensionPixelSize(com.tywj.navigation.R.dimen.dp_1)
                    }
                }
            }
        })
    }
}